package com.taxi.driver.module.main.mine.statistical;

import com.qianxx.utils.RxUtil;
import com.taxi.driver.R;
import com.taxi.driver.common.BasePresenter;
import com.taxi.driver.data.user.UserRepository;
import com.taxi.driver.module.vo.AssessmentStatisticalVO;

import javax.inject.Inject;

public class AssessmentStatisticalPresenter extends BasePresenter implements AssessmentStatisticalContract.Presenter {
    UserRepository mUserRepository;
    AssessmentStatisticalContract.View mView;

    @Inject
     AssessmentStatisticalPresenter(UserRepository userRepository,AssessmentStatisticalContract.View view) {
        mUserRepository = userRepository;
        mView = view;
    }

    @Override
    public void reqAssessmentStatistical(String startTime,String endTime) {
        mUserRepository.reqAssessment(startTime,endTime)
                .map(AssessmentStatisticalVO::createFrom)
                .compose(RxUtil.applySchedulers())
                .doOnSubscribe(() -> mView.showLoadingView(true))
                .doAfterTerminate(() -> mView.hideLoadingView())
                .subscribe(vo -> {
                    mView.showAssessmentStatistical(vo);
                }, ex -> {
                    showNetworkError(ex, R.string.network_error,mView,mUserRepository);
                });
    }
}
